﻿
var ns, toast, actionsheet, UIActionProgress;
var app = new Vue({
    el: '#app',
    data: {
        userinfo: {
            headimg: '../image/default.png',
            username: '',
            phonenumber: '',
            loginname: '',
            sex:'',
            positionname:'',
        },
        appVersion:"",
        appUpdata:0//1最新版 2有跟新
    },
    methods: {
        get_data: function() {
            var that = this;
            var options={};

            ns.post(options, function (succeed, data, err) {
                console.log(JSON.stringify(data));
                that.appVersion = api.appVersion;//app版本号
                if(succeed){
                    that.userinfo=data
                }else{
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
                
                // if(data.status){
                //     that.userinfo.headimg = data.headimg || '../image/default.png';
                //     that.userinfo.username = data.username;
                //     that.userinfo.phonenumber = data.phonenumber;
                //     that.userinfo.loginname = data.loginname;
                //     that.userinfo.sex = data.sex;
                //     that.userinfo.positionname = data.positionname;
                // };
            },{
                command: 'App/Auth/GetUser'
            });
            that.getAppVersionIsUpdate();
        },
        getAppVersionIsUpdate: function(){
            let that = this;
            var options={}; 
            options.appType='android';//此处传android 或者ios
            options.versionType=1;//此处固定传1,1=员工端 2=其他，后续接口扩展
            options.version='';//APP版本
            ns.post(options, function(succeed, data, err) {
                if(data && data.canUpdate) that.appUpdata=2;
                else  that.appUpdata=1;
            }, {
                is_getapi: true,
                command: 'App/System/GetAppVersion'
            });
        },
        // change_nickname: function() {
        //     ns.openWin('xiugainicheng_frm', '修改昵称');
        // },
        // change_phone: function() {
        //     ns.openWin('xiugaidianhua_frm', '修改手机号码');
        // },
       
        // 修改密码
        // changepwd: function() {
        //     ns.openWin('xiugaimima_frm', '修改密码');
        // },
        // 版本更新
        // checkupdate: function() {
        //     appupgrade.check_upgrade(true);
        // },
        // 退出登录
        logout: function() {
            api.confirm({
                title: '提示',
                msg: '确定退出当前账号',
                buttons: ['确定', '取消']
            }, function(ret, err) {
                if (ret.buttonIndex == 1) {
                    ns.removeUid(true);
                };
            });
        }
    }
});
apiready = function() {
    api.parseTapmode();
    ns = window.Foresight.Util;
    toast = new auiToast();
    actionsheet = new auiActionsheet();
    UIActionProgress = api.require('UIActionProgress');
    app.get_data();
    // api.addEventListener({
    //     name: 'changecentersuccess'
    // }, function() {
    //     app.get_data();
    // });
}
